package com.nova.edc.service.system.impl;

import com.nova.edc.dao.system.GroupDao;
import com.nova.edc.model.system.Group;
import com.nova.edc.service.system.GroupService;
import com.nova.frame.dao.criterion.Restrictions;
import com.nova.frame.utils.JdbcUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class GroupServiceImpl implements GroupService {

    @Autowired
    private GroupDao novaGroupDao;

    @Override
    public List<Group> findAllGroup() {
        return novaGroupDao.findAll();
    }

    @Override
    public List<Group> findByExample(Group group) {
        return novaGroupDao.findByExample(group);
    }

    @Override
    public Group getByGroupName(String groupname) {
        return novaGroupDao.query().add(Restrictions.eq("t_group.GroupName", groupname)).get();
    }

    @Override
    public Group getByGroupCode(Integer groupCode) {
        return novaGroupDao.query().add(Restrictions.eq("t_group.GroupCode", groupCode)).get();
    }

    @Override
    public List<String> findAllGroupName() {
        String sql = "SELECT GroupName FROM t_group";
        List<String> list = JdbcUtils.query(String.class, sql);
        return list;
    }
}
